This is the first part of the Bitwise Operators in C++ which introduces us to the first 3 of the 6 bitwise operators in C++, namely:
This is the second part of the Bitwise Operators in C++ which introduces us to the last 3 of the 6 bitwise operators in C++, namely:

Hello World
GeeksforGeeks - A computer science portal for geeks
Enter your age:
Input : 18
Your age is: 18
An error occured
An error occured
Hello World!
A preprocessor directive is a statement which gets processed by the C++ preprocessor before compilation.

#include <file_name>where file_name is the name of file to be included. The '<' and '>' brackets tells the compiler to look for the file in standard directory.
#include "filename"

Perimeter of Circle: 31.4159
Area of Circle: 78.5398
#define f(l,r) for (int i = l; i < r; i++)
#define ll long long
#define ull unsigned long long
#define abs(x) (x < 0 ? (-x) : x)
Variables Contd.
Scope of Variables
Compilation Error:
prog.cpp: In function 'int main()':
prog.cpp:14:37: error: 'age' was not declared in this scope
cout << "Outside Function: " << age << endl;
^
Access inside func: 10
Access inside main: 10
Value of global x is 5
Value of local x is 10
Data-type Modifiers
These are special keywords modifying the size of a particular data-type:| Data Type | Size (in bytes) | Range |
|---|---|---|
| short int | 2 | -32,768 to 32,767 |
| unsigned short int | 2 | 0 to 65,535 |
| int | 4 | -2,147,483,648 to 2,147,483,647 |
| unsigned int | 4 | 0 to 4,294,967,295 |
| long int | 4 | -2,147,483,648 to 2,147,483,647 |
| unsigned long int | 4 | 0 to 4,294,967,295 |
| long long int | 8 | -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 |
| unsigned long long int | 8 | 0 to 18,446,744,073,709,551,615 |
| char | 1 | -128 to 127 |
| unsigned char | 1 | 0 to 255 |
| float | 4 | 3.4E +/- 38 (7 digits) |
| double | 8 | 1.7E +/- 308 (15 digits) |
| long double | 8 | same as double |
| wchar_t | 2 | 0 to 65,535 |
1 1
2 2
3 3
bool -> char -> short int -> int ->
unsigned int -> long -> unsigned ->
long long -> float -> double -> long double
x = 107
y = a
z = 108
(type) expressionwhere type indicates the data type to which the final result is converted.
Sum = 2
3
I'm in Child
Old roll number: 3
New roll number: 5
c = a + b;

Add & Assign: 18
Subtract & Assign: 12
Multiply & Assign: 72
Divide & Assign: 12
int a = 10, b = 2, c = 4;
a %= b; // a = (10 % 2) = 0
a %= c; //a = (10 % 4) = 2
AND & Assign: 4
OR & Assign: 6
XOR & Assign: 15
Left-shift & Assign: 30
Right-shift & Assign: 15
6
6
7
(20 % 3) = 2
(~ 20) = -21
20 in binary (8-bit): 00010100
(~ 20): 11101011, which is -21 in 2's complement form
for negative integers.
(5 << 2) = 20
5 in binary: 101
left-shift by 2 places: 10100 ~ 20 (in decimal)
(30 >> 3) = 3
30 in binary: 11110
right-shift by 3 places: 11 ~ 3 (in decimal)
a == b: 0
a != b: 1
a < b: 1
a > b: 0
a <= c: 1
b >= c: 1
Negation: 0
AND: 0
OR: 1
1
0
1
4th element of the array (0-indexing): 4
Access via Pointer: 6
Value changed via pointer: 5
Address of b: 0x7ffdc51518d4
Direct Access: 5
Pointer Access: 5
Direct Access of Pointer: 10
Pointer Access of Pointer: 10
A *aptr = new A("Class A Instance");
delete aptr; //frees memory pointed to by aptr
int a;
cout<< sizeof(a); //prints 4
int value = (flag) ? value1 : value2
char p = (char)(65);
cout << (double)(2);
Operator Precedence
Below given is the precedence table of the various operators and their corresponding associativity:| Precedence | Operator | Description | Associativity |
|---|---|---|---|
| 1 | a++ a-- a( ) a[ ] . -> |
Post-increment/decrement Function call Array subscript Member access |
Left-to-right |
| 2 | ++a --a +a -a ! ~ (type) *a &a sizeof new delete |
Pre-increment/decrement Unary plus & minus Logical NOT & bitwise NOT Type-casting Dereferencing Address-of sizeof Dynamic Memory Allocation Memory De-allocation |
Right-to-left |
| 3 | *(a.b) *(a->b) |
Pointer to member | Left-to-right |
| 4 | a*b a/b a%b |
Multiplication, division & remainder | Left-to-right |
| 5 | a+b a-b |
Addition & subtraction | Left-to-right |
| 6 | << >> | Bitwise left-shift and right-shift | Left-to-right |
| 7 | < <= > >= |
Relational operators < and ≤ Relational operators > and ≥ |
Left-to-right |
| 8 | == != |
Relational operators = and ≠ |
Left-to-Right |
| 9 | & | Bitwise-AND | Left-to-right |
| 10 | ^ | Bitwise-XOR | Left-to-right |
| 11 | | | Bitwise-OR | Left-to-right |
| 12 | && | Logical AND | Left-to-right |
| 13 | || | Logical OR | Left-to-right |
| 14 | a?b:c = += -= *= /= %= <<= >>= &= ^= |= |
Ternary/conditional Assignment Assignment (sum, difference) Assignment (multiply, divide, modulo) Assignment (left-shift, right-shift) Assignment (AND, XOR, OR) |
Right-to-left |
| 15 | , | Comma | Left-to-right |
Character p changed to: P
Character P changed to: p
47 deg Celsius in Fahrenheit: 116.6
29 deg Celsius in Fahrenheit: 84.2
24.00
Min. notes to get a sum of 253: 6